package freshmanspecial.mredrock.com.welcomefreshman.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import freshmanspecial.mredrock.com.welcomefreshman.Bean.MilitaryTrainingPhotoBean;
import freshmanspecial.mredrock.com.welcomefreshman.R;
import freshmanspecial.mredrock.com.welcomefreshman.View.PictureView;

/**
 * Created by Administrator on 2017/8/11 0011.
 */

public class TrainRecyclerAdapter extends RecyclerView.Adapter<TrainRecyclerAdapter.MyTrainViewHolder> {
    private MilitaryTrainingPhotoBean bean;
    private Context context;
    public TrainRecyclerAdapter(MilitaryTrainingPhotoBean bean, Context context){
        this.bean = bean;
        this.context = context;
    }
    @Override
    public MyTrainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.special_2017_train_recycler_item,parent,false);
        MyTrainViewHolder myTrainViewHolder = new MyTrainViewHolder(view);
        return myTrainViewHolder;
    }

    @Override
    public void onBindViewHolder(MyTrainViewHolder holder, final int position) {
        Glide.with(context).load(bean.getData().getUrl().get(position)).into(holder.imageView);
        holder.textView.setText(bean.getData().getTitle().get(position));
        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(context,PictureView.class);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return bean.getData().getUrl().size();
    }

    class MyTrainViewHolder extends RecyclerView.ViewHolder{
        ImageView imageView ;
        TextView textView;
        public MyTrainViewHolder(View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.train_recycler_item_img);
            textView = itemView.findViewById(R.id.train_recycler_item_text);
        }
    }
}
